package mysql

import (
	"video/videorpc/videorpc"

	"gorm.io/gorm"
)

type Video struct {
	gorm.Model
	Title  string `gorm:"type:varchar(30);not null;comment:视频标题"`
	Image  string `gorm:"type:varchar(30);not null;comment:视频图片"`
	Author string `gorm:"type:varchar(30);not null;comment:视频作者"`
	Desc   string `gorm:"type:varchar(30);not null;comment:视频描述"`
}

func (v *Video) VideoShow(db *gorm.DB, id int64) error {
	return db.Debug().Where("id=?", id).Find(v).Error
}

func VideoList(db *gorm.DB) []*videorpc.VideoList {
	var list []*videorpc.VideoList

	db.Model(&Video{}).
		Select("videos.id as video_id,title,image,author,'desc'").
		Debug().Find(&list)

	return list
}
